
/*
let obj = Object.assign({}, obj1, obj2, )
let obj = {
  ...obj1,
  ...obj2
}
Object.keys(obj)
Object.values(obj)

[].forEach()
let res = [].map()
let res = [].filter()
let res = [].every()
let res = [].some()
let res = [].find()
let res = [].findIndex()
let res = [].reduce((prev, current, currentIndex) => prev + current)
*/


let arr = ['hello', 1, 99, 'world', '!!!']
let arr1 = [99, 123, 87, 0, 23]


// let res = arr1.reduce((前一项, 当前项, 当前项下标) => {
/*let res = arr1.reduce((sum, item, index) => {
  // console.log(sum)
  // console.log(index)
  // console.log(item)
  return sum + item
})*/


// 某些项符合条件返回布尔值
/*let res = arr.some((item, index) => {
  return typeof item === 'object'
})*/

// 每一个都符合条件返回布尔值
/*let res = arr1.every((item, index) => {
  return typeof item === 'number'
  // return typeof item === 'string'
})*/

/*
// 过滤，返回符合条件的一个数组
let res = arr1.filter((item, index) => {
  // return typeof item === 'number'
  // return typeof item === 'string'
  return item > 50
})
*/

/*
返回数组，相当于构造一个数组
let res = arr1.map((item, index) => {
  return '$' + (item * 10).toFixed(3)
})*/

// 只用作循环，无返回值
/*arr.forEach((item, index) => {
  // console.log(item, index)
  return index
})*/

/*
let res = arr.find((item) => {
  // console.log(item)
  return item === 99
})

let res = arr.findIndex((item) => {
  // return item === 99
  return typeof item === 'number'
})*/










// ...rest字符
// ...扩展运算符

/*
const getQuery = () => {
  let str = '?cl=3&tn=baidutop10&fr=top1000&wd=%E5%B9%BF%E5%B7%9E%E6%B7%B1%E5%9C%B3%E6%9A%82%E5%81%9C%E5%9B%BD%E5%BA%86%E7%81%AF%E5%85%89%E7%A7%80&rsv_idx=2&rsv_dl=fyb_n_homepage&hisfilter=1'
  let arr = str.slice(1).split('&')
  let newArr = []
  for (let item of arr) {
    // console.log(item.split('='))
    newArr.push(item.split('='))
  }
  return Object.fromEntries(newArr)
}
const { cl, wd } = getQuery()
console.log(cl)
console.log(wd)
// console.log(getQuery().cl)
// console.log(getQuery().wd)
*/



let obj1 = {
  a: 1
}

let obj2 = {
  b: 'b',
  a: '99'
}

let obj3 = {
  c: 'c'
}


let obj4 = Object.assign({}, obj2, obj3, obj1)
// console.log(obj4)

// console.log(Object.keys(obj4))
// console.log(Object.values(obj4))
// console.log(Object.entries(obj4))
// console.log(Object.fromEntries(Object.entries(obj4)))
// console.log(Object.fromEntries(键值对的二维数组))

/*
Object.keys(obj4).forEach((item) => {
  console.log(obj4[item])
})*/


// 合并对象
// Object.assign(target, source1, source2)
// Object.assign(obj1, obj2, obj3)
// let obj4 = Object.assign({}, obj2, obj3, obj1)
/*let obj4 = {
  ...obj2,
  ...obj1,
  ...obj3
}*/
// console.log(obj4)

let person = {
  name: '张三',
  attr: {
    a: 1
  }
}
let person2 = JSON.parse(JSON.stringify(person)) // 深拷贝
// let person2 = Object.assign({}, person)
// let person2 = {
//   ...person
// }
person2.name = '李四'
person2.attr.a = 99

console.log(person2)
console.log(person)



